/*
Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

Credits:
Special thanks to @ts for adding this problem and creating all test cases.
*/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <sstream>
#include <unordered_set>
#include "print.h"
using namespace std;

/**
* Definition for binary tree*/
typedef __int32 uint32_t;


void testForStack()
{
	stack<int> mystack;
	mystack.push(10);
	mystack.push(20);
	mystack.top() -= 5;
	cout << "mystack.top() is now " << mystack.top() << endl;
}

void testForIntToString()
{
	int a = 10;
	stringstream ss;
	ss << a;
	string str = ss.str();
	cout << str << endl;

	string str1 = to_string(a);

}


class Solution {
public:
	
	int trailingZeroes(int n) {

		int result = 0;
		while (n)
		{
			result += n / 5;
			n /= 5;
		}
		return result;
	}
};



class Solution2 {
public:
	double Factorial(int n)
	{
		if (n == 0 || n == 1)
		{
			return 1;
		}
		else
		{
			return n * Factorial(n - 1);
		}
	}
	int trailingZeroes(int n) {

		cout << "start"<< endl;
		if (n == 0)
			return 0;

		double factNum = 0;
		factNum = Factorial(n);


		cout << "endFact" << factNum<< endl;

		double temp;
		int result = 0;


		while (factNum == 0)
		{
			
			if (fmod(factNum, 10) == 0)
			{
				factNum /= 10;
				result++;
			}
			else
			{
				factNum /= 10;

			}
		}
		return result;
	}
};



int main(int argc, char* argv[])
{


	int a = 0;

	for (int i = 1; i < argc; i++){


		cout << argv[i] << endl;
		a = atoi(argv[i]);
	}


	double f = 19;

	

	Solution s;
	//stackTree.push(p->left);
	//stackTree.push(p->right);

	cout << s.Factorial(a)<< endl;
	cout << s.trailingZeroes(10)<< endl;
	system("pause");
	return 0;
}